I want to call a JS function which is declared in this manner:
Extract of JS File
var SOMETHING;
void 0 === SOMETHING && (SOMETHING = {}), SOMETHING.init = function(config) {
SOMETHING.version = "1.1.0", console.log("SOMETHING.version: " + SOMETHING.version);
}
To run this, in TS file I use this way
let script = this._renderer2.createElement('script');
script.type = `text/javascript`;
script.text = `
var urlThing = '${urlThing }';
var exito = function (data) {
alert(JSON.stringify(data));
};
var error = function (data) {
alert(JSON.stringify(data));
};
SOMETHING.init(); //----> the function that I want to call on TS
`;
this._renderer2.appendChild(this._document.body, script);
I want to run this in TS directly instead use a script. I tried this way:
Angular.json
"scripts": ["src/assets/klap/KlapSandBox.js"]
TS File that I want to run the function
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { KlapService } from '../../services/klap.service';
declare function SOMETHING.init();
This throws an error that .init is not found (Cannot find name 'init') and I can't find a solution about that.
Any Suggestions?